from venya.lib import stdlib

class GypsumError(Exception):
    pass

class Base(object):
    def __init__(self):
        super(Base, self).__init__()
        self._linenum = 0
        self._name = None

    def error(self, fmt, *args):
        errmesg = None
        if len(args):
            errmesg = stdlib.sprintf(fmt, *args)
        else:
            errmesg = str(fmt)

        raise GypsumError(errmesg)

    def GetLineNumber(self):
        return self._linenum

    def SetLineNumber(self, Value):
        try:
            self._linenum = int(Value)
        except ValueError:
            self.error("INTERNAL ERROR, cannot coerce value to integer")

    def GetName(self):
        return self._name

    def SetName(self, Name = None):
        if Name:
            self._name = str(Name)

    name = property(GetName, SetName)
    line = property(GetLineNumber, SetLineNumber)


